package com.lagou.assignment.dao;

import com.lagou.assignment.model.Admin;
import com.lagou.assignment.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.beans.JavaBean;
import java.sql.SQLException;
import java.util.Arrays;

public class AdminDaoImp implements AdminDao{

    @Override
    public Admin adminLogin(Admin admin) throws SQLException {
        //1.创建QueryRunner
        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

        //2.编写sql
        String sql = "select * from admin where username = ? and password = ?";

        //3.执行查询
        Object[] param = {admin.getUsername(), admin.getPassword()};
        Admin admin1 = qr.query(sql, new BeanHandler<Admin>(Admin.class), param);

        //4.获取数据
        System.out.println(admin1);

        return admin1;
    }
}
